package com.kgc.scd.controller;

import com.kgc.scd.constant.CommonConstant;
import com.kgc.scd.service.WebGoodsCommentService;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import com.kgc.scd.vo.ShopCarouselVO;
import com.kgc.scd.vo.ShopGoodsVO;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created On : 2022/11/15.
 * <p>
 * Author : 22166
 * <p>
 * Description: WebGoodsCommentInfo
 */

@RestController
@Api(tags = "操作入口")
public class WebGoodsCommentController {



    @Resource
    private WebGoodsCommentService webGoodsCommentService;


    /**
     * @author : 22166
     * @date   : 2022/11/14
     * @param  : [pageNo, pageSize]
     * @return : com.kgc.scd.util.RequestResult<java.util.List<com.kgc.scd.bean.ShopCommentVO>>
     * @description : 查询商品详情和评论列表带分页
     */
    @GetMapping("/shopCommentList")
    @ApiOperation(value = "查询商品详情+评论列表", notes = "基于mybatis-plus，查询评论列表，支持统一返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "条数", required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response= ShopGoodsVO.class),
    })
    public RequestResult<?> shopCommentList(@RequestParam(name = "goodsId") String goodsId,
                                            @RequestParam(name = "pageNo") Integer pageNo,
                                            @RequestParam(name = "pageSize") Integer pageSize){
        int count = pageNo;
        Map<String,Object> objectMap = new TreeMap<>();
        objectMap.put("a-goodsInfo",webGoodsCommentService.selectGoodsInfoWeb(goodsId));
        objectMap.put("b-commentInfo",webGoodsCommentService.getCommentListPageWeb(goodsId,pageNo,pageSize));
        // 调用业务接口，查询评论详情
        return ResultBuildUtil.success(objectMap);
    }



    /**
     * @author : 22166
     * @date   : 2022/11/15
     * @param  : []
     * @return : JSONResult
     * @description : 获取轮播图
     */
    @GetMapping("/carousel")
    @ApiOperation(value = "获取首页轮播图",notes = "获取首页轮播图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id")
    })
    public RequestResult<List<ShopCarouselVO>> carousel(){


        return ResultBuildUtil.success(webGoodsCommentService.queryAllWeb());
    }

    /**
     * @author : 崔佳伟
     * @date   : 2022/11/23
     * @param  : [id, goodsId]
     * @return : int
     * @description : 根据轮播图id，更新轮播图对应商品
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新",notes = "更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "轮播图id", required = true),
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true)
    })
    public int update(String id,String goodsId){
        return webGoodsCommentService.updateShopCarousel(id,goodsId);
    }

}